package com.netease;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import java.io.IOException;

/**
 * @projectName: modeling-dev
 * @package: com.netease
 * @className: FeishuApiCall
 * @author: aochong
 * @description: TODO
 * @date: 2023/4/27 09:40
 * @version: 1.0
 */
public class FeishuApiCall {
    public static void main(String[] args) throws IOException {
        // 飞书机器人的 webhook 地址
        String url = "https://open.feishu.cn/open-apis/bot/v2/hook/19284c9a-a3af-452d-86e4-e43ccede8339";
        // 要发送的消息内容
        String message = "{\n" +
                "    \"msg_type\": \"text\",\n" +
                "    \"content\": {\n" +
                "        \"text\": \"这是一条来自机器人的测试消息！\"\n" +
                "    }\n" +
                "}";
        // 定义发送消息的请求体
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), message);
        // 发送HTTP POST请求
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();
        Response response = client.newCall(request).execute();
        // 输出响应状态码和内容
        System.out.println("Status code: " + response.code());
        System.out.println("Response content: " + response.body().string());
    }

}
